import time
from machine import PWM, Pin
from face import init_eyes, blink, smail, happy, anger, cry, random_weights

# def randface():
#     last_emotion = None
#     default_emo = blink
#     while True:
#         weights = {init_eyes: 10, blink: 10, smail: 5, happy: 3, anger: 2, cry: 2}
#         emotion = random_weights(weights)
#         # 避免两个表情生硬切换，每次变化前都先切到初始表情
#         if last_emotion != default_emo:
#             emotion = default_emo
#         if last_emotion != emotion:
#             emotion()
#             last_emotion = emotion
#             time.sleep(2)
#
#
# randface()

import time
from machine import Pin
from libs.ServoAPI import Servo

# 定义舵机控制对象
head = Servo(Pin(33), max_us=2500)
fl_2 = Servo(Pin(25), max_us=2500)
fl_3 = Servo(Pin(26), max_us=2500)
fl_4 = Servo(Pin(23), max_us=2500)
fl_5 = Servo(Pin(22), max_us=2500)

ang = 90
while True:
    fl_2.turn(ang)
    fl_4.turn(ang)
    fl_3.turn(180 - ang)
    fl_5.turn(180 - ang)
    ang = [180, 90][ang == 180]
    time.sleep(2)

# 程序入口
# if __name__ == '__main__':
#     while True:
#         head.write_angle(45)
#         time.sleep(2)
#         fl_2.write_angle(0)
#         time.sleep(2)
#
#         head.write_angle(135)
#         fl_2.write_angle(180)
#         time.sleep(2)
